﻿
using System;
using UnityEngine;

namespace SillyCube
{
    public class CameraController : MonoBehaviour
    {
        public float cameraLerpSpeed = 1f;
        
        private void Start()
        {
        }

        private void LerpToCube(CubeController controller)
        {
            var pos = controller.transform.position;
            pos.z = -10;
            pos.y += 3f;

            transform.position = Vector3.Lerp(transform.position, pos, Time.deltaTime * cameraLerpSpeed);
        } 

        private void Update()
        {
            var controller = GameManager.Instance.CubeContainer.CurrentCubeController;
            if (controller is null) 
                return;
            
            if (controller.OnCameraTick(transform))
            {
                LerpToCube(controller);
            }
        }
    }
}